package com.probox.common.core.utils;



import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

public class HttpUtil {
    public static String getIp(HttpServletRequest request) {
        String ip = request.getHeader("x-forwarded-for");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }

    @SuppressWarnings("rawtypes")
	public static Map<String, String> getRequestParameters(HttpServletRequest request) {
		Map<String, String> params = new HashMap<>();
		Enumeration nameEnum = request.getParameterNames();
		while (nameEnum.hasMoreElements()) {
			String name = (String) nameEnum.nextElement();
			params.put(name, request.getParameter(name));
		}

		return params;
	}




}
